
cmake_minimum_required(VERSION 3.9.0)

set(CMAKE_VERBOSE_MAKEFILE ON)
set (PACKAGE_NAME "swisseph")
project(${PACKAGE_NAME})

set(OH_MODULE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../oh_modules")
set(RNOH_APP_DIR "${CMAKE_CURRENT_SOURCE_DIR}")

set(RNOH_CPP_DIR "${OH_MODULE_DIR}/@rnoh/react-native-openharmony/src/main/cpp")

set(SWISSEPH_DEPENDENCY_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../../../node_modules/react-native-swisseph/")
set(SWISSEPH_DEPENDENCY_CPP_DIR "${SWISSEPH_DEPENDENCY_DIR}/cpp")
set(SWISSEPH_DEPENDENCY_LIB_DIR "${CMAKE_CURRENT_SOURCE_DIR}/swisseph")

file(GLOB SWISSEPH_ROOT_SRC "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp")
file(GLOB SWISSEPH_DEPENDENCY_CPP_SRC "${SWISSEPH_DEPENDENCY_CPP_DIR}/*.cpp")
file(GLOB SWISSEPH_DEPENDENCY_LIB_SRC "${SWISSEPH_DEPENDENCY_LIB_DIR}/*.c" "${SWISSEPH_DEPENDENCY_LIB_DIR}/lib/*.c")

#set(CMAKE_ASM_FLAGS "-Wno-error=unused-command-line-argument -Qunused-arguments")
#set(CMAKE_CXX_FLAGS "-fstack-protector-strong -Wl,-z,relro,-z,now,-z,noexecstack -s -fPIE -pie")
#add_compile_definitions(WITH_HITRACE_SYSTRACE)
#set(WITH_HITRACE_SYSTRACE 1) # for other CMakeLists.txt files to use
#add_subdirectory("${RNOH_CPP_DIR}" ./rn)


# Create a separate target for C files
add_library(swisseph_c OBJECT ${SWISSEPH_DEPENDENCY_LIB_SRC})
set_target_properties(swisseph_c PROPERTIES
    C_STANDARD 11
    C_STANDARD_REQUIRED ON
)


target_include_directories(swisseph_c PRIVATE
    ${SWISSEPH_DEPENDENCY_LIB_DIR}
    "${SWISSEPH_DEPENDENCY_LIB_DIR}/lib"
)


# Main library target (C++ files)
add_library(${PACKAGE_NAME} SHARED
 ${SWISSEPH_ROOT_SRC}
 ${SWISSEPH_DEPENDENCY_CPP_SRC}
)

set_target_properties(${PACKAGE_NAME} PROPERTIES
    CXX_STANDARD 17
    CXX_STANDARD_REQUIRED ON
)

target_include_directories(${PACKAGE_NAME} PUBLIC
    ${CMAKE_CURRENT_SOURCE_DIR}
    ${SWISSEPH_DEPENDENCY_LIB_DIR}
    "${SWISSEPH_DEPENDENCY_LIB_DIR}/lib"
)

# Link C object files to the main library
target_link_libraries(${PACKAGE_NAME} PUBLIC rnoh swisseph_c libhilog_ndk.z.so)

# Disable specific warnings for C files
if(CMAKE_C_COMPILER_ID MATCHES "Clang")
    target_compile_options(swisseph_c PRIVATE
        -Wno-unused-command-line-argument
        -Qunused-arguments
    )
endif()